﻿using System;

namespace 作业四
{
    class Program
    {
        public int id;
        //生成只读字段
        public readonly string name = "ded";

        //只能在当前程序集访问
        internal static int age = 18;
        internal void Hi()
        {
            Console.WriteLine(age);
        }
        //当前类内部及所有子类内部都可以访问
        protected int score = 100;


        public class myClass1
        {
            /// <summary>/// 虚方法，用来显示信息/// </summary>
            public virtual void ShowInfo()
            {
            }
        }
        public sealed class myClass2 : myClass1       //密封类，继承自myClass1
        {
            private string id = "";

            private string name = "";

            /// <summary>/// 编号属性/// 
            ///</summary>
            public string ID
            {
                get { return id; }
                set { id = value; }
            }
            /// <summary>/// 名称属性/// </summary>
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            /// <summary>/// 密封并重写基类中的ShowInfo方法/// 
            /// </summary>
            public sealed override void ShowInfo()
            {
                Console.WriteLine(ID + " " + Name);
            }
        }




        static void Main(string[] args)
        {

            Program p = new Program();
            p.id = 01;
            Console.WriteLine(age);
            Console.WriteLine(p.id);
            myClass2 myclass2 = new myClass2();
            //实例化密封类对象myclass2.ID = "0001";  
            //为密封类中的编号属性赋值
            myclass2.Name = "xiaoyou";              //为密封类中的名称属性赋值
            myclass2.ShowInfo();               //调用密封类中的密封方法} 

        }
    }
    class Student : Program
    {
        public void Score()
        {
            Console.WriteLine(score);
        }
    }
    abstract class AbstractClass
    {
        public abstract void Method();
    }
    /// <summary>
    /// 密封类不能被继承并且不能和抽象类同时用
    /// </summary>
    /// 
    public sealed class Hellow
    {
        private readonly string name1 = "xiaohong";

    }
    sealed class SealedClass : AbstractClass
    {
        public override void Method()
        {

        }
    }
    abstract class A
    {

        protected double x = 0, y = 0;
        public A(double a, double b)
        {

        }

        public abstract void area();  //抽象方法，不能有方法体
    }

    class S : A
    {
        public S(double a, double b) : base(a, b) { }
        public override void area()
        { //不能有new,必须用overrride
            Console.WriteLine(x * y);
        }
    }
}
